package com.limingru.newbee.config;

import com.limingru.newbee.config.handler.TokenToUserMethodArgumentResolver;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class NewBeeWebMvcConfig implements WebMvcConfigurer {

    public final static String workStaticAddress = "C:\\Users\\18813\\Desktop\\study\\newbee-mall-api\\src\\main\\resources\\upload\\upload\\";

    public final static String homeStaticAddress = "/Users/limingru/Desktop/images/upload/";

    @Autowired
    private TokenToUserMethodArgumentResolver tokenToUserMethodArgumentResolver;

    /**
     * TokenToUser 注解处理方法
     * @param resolvers
     */
    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(tokenToUserMethodArgumentResolver);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/goods-img/**").addResourceLocations("file:" + workStaticAddress);
        registry.addResourceHandler("/upload/**").addResourceLocations("file:" + workStaticAddress);
    }
}
